'use strict';

module.exports = appInfo => {

  // console.log('config.default,js=======>', appInfo);

  const config = exports = {};

  config.keys = 'xx1122';
  // 'authToken',
  config.middleware = [ 'robot', 'errorHandler', 'formatResponse' ];

  // config.logger = {
  //   level: 'NONE',
  // };

  config.errorHandler = {
    match: '/api',
  };

  config.authToken = {
    secretKey: 'zG@YLg',
    ignore: [ '/api/v2/login' ],
  };

  config.validate = {
    // convert: false,
    // validateRoot: false,
  };

  config.robot = {
    ua: [ /Baiduspider/i ],
  };

  // change to your own sequelize configurations
  config.sequelize = {
    dialect: 'postgres',
    delegate: 'model',
    baseDir: 'model',
    host: 'localhost',
    port: 5432,
    database: 'simple',
    username: 'postgres',
    password: '123456',
    benchmark: true,
    // operatorsAliases: false,  特性移除
    define: {
      freezeTableName: false,
      underscored: true,
    },
  };

  config.security = {
    csrf: {
      queryName: '_csrf', // 通过 query 传递 CSRF token 的默认字段为 _csrf
      bodyName: '_csrf', // 通过 body 传递 CSRF token 的默认字段为 _csrf
      headerName: 'x-csrf-token', // 通过 header 传递 CSRF token 的默认字段为 x-csrf-token
      enable: false,
      ignore: ctx => ctx.request.url.includes('/login'),
    },
  };

  // 静态资源
  config.view = {
    mapping: {
      '.js': 'assets',
    },
  };

  config.assets = {
    devServer: {
      command: 'roadhog dev',
      port: 8000,
    },
  };


  // config.io = {
  //   init: {
  //     wsEngine: 'ws',
  //   }, // passed to engine.io
  //   namespace: {
  //     '/': {
  //       connectionMiddleware: [ 'auth' ],
  //       // packetMiddleware: [ 'filter' ],
  //     },
  //     '/chat': {
  //       connectionMiddleware: [ 'auth' ],
  //       // packetMiddleware: [],
  //     },
  //   },
  //   // 通过 Redis 实现数据共享
  //   redis: {
  //     host: '127.0.0.1',
  //     port: 6379,
  //   },
  // };

  config.redis = {
    // your redis configurations
    client: {
      host: '127.0.0.1',
      port: 6379,
      password: null,
      db: 0,
    },

  };

  config.session = {
    // 使用 koa-session 的默认值
  };

  config.cors = {
    origin: [ 'http://localhost:9527' ],
    credentials: true,
    allowMethods: 'GET,HEAD,PUT,POST,DELETE,PATCH',
  };

  // 直接使用 ctx.session 进行读取，存储，这里使用了外部 redis
  return config;
};


/*
// cookie 校验实践
config.authCookie = {
    ignore: [ '/api/v2/cookieOfLogin' ],
  };


*/
